from django.db import models

# Create your models here.
class Simulation(models.Model):
    sim_start_date = models.DateTimeField('fictional date started')
    actual_start_date = models.DateTimeField('actual date started')

    def __unicode__(self):
        return "simulation %s %s"%(self.pk,self.sim_start_date)

class Owner(models.Model):
    first_name = models.CharField(max_length=100)
    middle_name = models.CharField(max_length=100)
    last_name = models.CharField(max_length=100)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

    def __unicode__(self):
        return "%s %s %s"%(self.first_name,self.middle_name,self.last_name)

class Farm(models.Model):
    owner_ids = models.ManyToManyField(Owner)
    farm_name = models.CharField(max_length=100)
    start_date = models.DateTimeField('date herd started')
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)
    
    def __unicode__(self):
        return "farm %s"%(self.farm_name)

class Herd(models.Model):
    owner_ids = models.ManyToManyField(Owner)
    farm = models.ForeignKey(Farm)
    start_date = models.DateTimeField('date herd started')
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)
    
    def __unicode__(self):
        return "herd %s"%(self.farm)

class Food(models.Model):
    food_name = models.CharField(max_length=100)
    cost_per_lbs = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class Food_Purchase(models.Model):
    food_id = models.ForeignKey(Food)
    weight = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class Diet(models.Model):
    food_id = models.ForeignKey(Food)
    lbs_per_day = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class Medicine(models.Model):
    medicine_name = models.CharField(max_length=100)
    cost_per_use = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class VeterinaryVisit(models.Model):
    veterinarion_name = models.CharField(max_length=100)
    cost = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class Alpaca(models.Model):
    owner_ids = models.ManyToManyField(Owner)
    herd = models.ForeignKey(Herd)
    name = models.CharField(max_length=100)
    birth_date = models.DateTimeField('date alpaca born')
    ALPACA_BREEDS = (
                ('HUACAYA','H'),
                ('SURI','S'),
            )
    breed = models.CharField(max_length=1,choices=ALPACA_BREEDS,default='HUACAYA')
    ALPACA_SEXES = (
            ('MALE','M'),
            ('FEMALE','F'),
            )
    sex = models.CharField(max_length=1,choices=ALPACA_SEXES,default='FEMALE')
    pregnant = models.BooleanField()
    proven = models.BooleanField()
    price = models.DecimalField(max_digits=7,decimal_places=2)
    ALPACA_FIBER_COLORS = (
                ('WHITE', 'WH'),
                ('GREY', 'GY'),
                ('BROWN', 'BR'),
                ('RED', 'RD'),
                ('BLACK', 'BL'),
            )
    fiber_color = models.CharField(max_length=2,choices=ALPACA_FIBER_COLORS,default='WHITE')
    fiber_quality_microns = models.DecimalField(max_digits=3,decimal_places=2)
    fiber_only = models.BooleanField()
    ari = models.CharField(max_length=20)
    disposition = models.CharField(max_length=100)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)
    diet = models.ForeignKey(Diet) 

    def __unicode__(self):
        return "Alpaca %s"%(self.name)

class Mating(models.Model):
    dam = models.ForeignKey(Alpaca,related_name="cria_of_female")
    sire = models.ForeignKey(Alpaca,related_name="cria_of_male")
    cria = models.ManyToManyField(Alpaca)
    date_impregnated = models.DateTimeField('approximate date of latest impregnation')
    income = models.DecimalField(max_digits=7,decimal_places=2)
    cost = models.DecimalField(max_digits=7,decimal_places=2)
    sucess = models.BooleanField()
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class CompetitionEvent(models.Model):
    competition_date = models.DateTimeField('date that competition event occured')
    competition_name = models.CharField(max_length=100)
    competitor = models.ForeignKey(Alpaca)
    COMPETITION_TYPE = (
                ('HALTER','H'),
                ('FIBER','F'),
                ('COSTUME','C'),
            )
    competition_type = models.CharField(max_length=1,choices=COMPETITION_TYPE,default='HALTER')
    prize_money = models.DecimalField(max_digits=7,decimal_places=2)
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

class Sheering(models.Model):
    alpaca = models.ForeignKey(Alpaca)
    cost = models.DecimalField(max_digits=4,decimal_places=2)
    primary_fiber_oz = models.DecimalField(max_digits=4,decimal_places=2)
    secondary_fiber_oz = models.DecimalField(max_digits=4,decimal_places=2)
    ALPACA_FIBER_COLORS = (
                ('WHITE', 'WH'),
                ('GREY', 'GY'),
                ('BROWN', 'BR'),
                ('RED', 'RD'),
                ('BLACK', 'BL'),
            )
    fiber_quality_microns = models.DecimalField(max_digits=3,decimal_places=2)
    fiber_color = models.CharField(max_length=2,choices=ALPACA_FIBER_COLORS,default='WHITE')
    sim_date = models.DateTimeField('fictional date stamp')
    sim_id = models.ForeignKey(Simulation)

